﻿using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;

namespace Yoozoo.Gameplay.Liberty.AI.Node
{
    [Category("Ggame/Liberty")]
    public class NpcTriggerBoxingAnimation : AIBaseNode
    {
        protected override void OnExecute()
        {
            // 检测自身状态
            AnimationAgent animationAgent = _entity.viewer.animationAgent;
            if (!animationAgent.CanDoNextAnimation())
            {
                EndAction(false);
                return;
            }
            
            BattleAgent battleAgent = _entity.battleAgent;
            // // 转向目标
            // battleAgent.FaceToCurrentLockTarget();

            AIData aiData = _entity.data;
            if (Vector3.Dot(aiData.moveDirection, animationAgent.transform.forward)>0 && aiData.moveSpeed > 3.5f)
            {
                animationAgent.PlayBoxingCombo2();
            }
            else
            {
                animationAgent.PlayBoxingCombo1();
            }
            
            // {
            //     // 是否在缓冲时间内再次出招
            //     if (Time.time < animationAgent.nextComboBufferTimestamp)
            //     {
            //         switch (animationAgent.currentAnimationState)
            //         {
            //             case AnimationState.BoxingCombo1:
            //                 {
            //                     animationAgent.PlayBoxingCombo2();    
            //                 }
            //                 break;
            //             case AnimationState.BoxingCombo2:
            //                 {
            //                     if (Random.Range(0, 100) < 67)
            //                     {
            //                         animationAgent.PlayBoxingAttackKick();                                    
            //                     }
            //                     else
            //                     {
            //                         animationAgent.PlayBoxingCombo3();   
            //                     }
            //                 }
            //                 break;
            //
            //             case AnimationState.BoxingCombo3:
            //             case AnimationState.BoxingAttackKick:
            //             case AnimationState.BoxingAttackDown:
            //             case AnimationState.Idle:
            //             case AnimationState.Undefine:
            //                 {
            //                     animationAgent.PlayBoxingCombo1();
            //                 }
            //                 break;
            //         }
            //     }
            //     else
            //     {
            //         animationAgent.PlayBoxingCombo1();
            //     }
            // }

        }

        protected override void OnUpdate()
        {
            if (elapsedTime < 0.1f)
            {
                return;
            }
            
            AnimationAgent animationAgent = _entity.viewer.animationAgent;
            if (animationAgent.CanDoNextAnimation())
            {
                EndAction(true);
            }
        }

        
    }
}